<?php
namespace App\Http\Controllers\System;


use App\Common\Utils\JsonResponse;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

class TermController extends Controller
{

    private $logService;

    public function __construct()
    {
        parent::__construct();
        $this->middleware('auth');

         /** @var \App\Services\System\LogService $logService */
         $this->logService = app('logService');
    }

    /**
     * 获取学期列表
     * @author lxy
     * @datetime 2022-04-28
     */
    public function getTermList(Request $Request)
    {
        try
        {
            /** @var \App\Services\System\TermService $TermService */
            $TermService = app('termService');
            $result = $TermService->getTermList($Request->all());
            return JsonResponse::get($result['data'],TRUE,$result['total'],!empty($requestData['limit'])?$requestData['limit']:10);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * 设置学期
     * @author lxy
     * @datetime 2022-04-28
     */
    public function setTerm(Request $Request)
    {
        try
        {
            /** @var \App\Services\System\TermService $TermService */
            $TermService = app('termService');
            $result = $TermService->setTerm($Request->all());
            if(!empty($Request->all()['id'])){
                $this->logService->log('301','学期编辑', "学期编辑");
            }else{
                $this->logService->log('300','学期新增', "学期新增");
            }
            
            return JsonResponse::get($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * 获取一条数据
     * @author lxy
     * @datetime 2022-04-28
     */
    public function getTermById(Request $Request)
    {
        try
        {
            /** @var \App\Services\System\TermService $TermService */
            $TermService = app('termService');
            $result = $TermService->getTermById($Request->all());
            return JsonResponse::get($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * 删除
     * @author lxy
     * @datetime 2022-04-28
     */
    public function delTerm(Request $Request)
    {
        try
        {
            /** @var \App\Services\System\TermService $TermService */
            $TermService = app('termService');
            $result = $TermService->delTerm($Request->all());
            $this->logService->log('302','学期删除', "学期删除");
            return JsonResponse::get($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    /**
     * 获取学期
     * @author lxy
     * @datetime 2022-04-29
     */
    public function getTermData(Request $Request)
    {
        try
        {
            /** @var \App\Services\System\TermService $TermService */
            $TermService = app('termService');
            $result = $TermService->getTermData($Request->all());
            return JsonResponse::get($result);
        }
        catch(\Exception $e)
        {
            return $this->error($e);
        }
    }

    

}

?>